/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#include "log.h"

#include <iostream>
#include <stdio.h>

// Old logging code. doesn't compile on mingw
/*
BOOST_DEFINE_LOG_FILTER(g_log_filter, boost::logging::filter::no_ts)
BOOST_DEFINE_LOG(g_l, log_type )

BOOST_DEFINE_LOG_FILTER(e_log_filter, boost::logging::filter::no_ts)
BOOST_DEFINE_LOG(e_l, log_type )

using namespace boost::logging;

void init_logs() {
	g_l()->writer().add_destination( destination::file("automate.log", destination::file_settings().initial_overwrite(true) ));
	g_l()->writer().add_formatter( formatter::append_newline() );
	g_l()->turn_cache_off();
	e_l()->writer().add_destination( destination::file("error.log", destination::file_settings().initial_overwrite(true) ));
	e_l()->writer().add_formatter( formatter::append_newline() );
	e_l()->turn_cache_off();
}
*/

std::string Logger::m_path;

void Logger::init(std::string path) {
	m_path = path;
	std::remove(m_path.c_str()); // Fix for windows not monitoring file if it already exists
	Logger::Instance(); // call once to create empty log file.
}

Logger::Logger() {
	m_file.open(m_path.c_str(), std::ios::trunc);
}

Logger::~Logger() {
	m_file.close();
}
